package com.range;

import com.google.common.collect.Range;
import com.google.common.primitives.Ints;
import org.junit.Test;

public class RangeDemo {
     /**
     *
     */
    @Test
    public void test01(){
        /**
         * 获取区间:
         *   (a..b)	    open(C, C)
         *   [a..b]	    closed(C, C)
         *   [a..b)	    closedOpen(C, C)
         *   (a..b]	    openClosed(C, C)
         *   (a..+∞)    greaterThan(C)
         *   [a..+∞)	atLeast(C)
         *   (-∞..b)	lessThan(C)
         *   (-∞..b]	atMost(C)
         *   (-∞..+∞)	all()
         */
        Range<Integer> range1 = Range.open(1, 10); //开区间
        Range<Integer> range2 = Range.closed(4, 6);  //闭区间
        //查询
        range1.isEmpty();
        range1.hasLowerBound(); //true 是否有下边界
        range1.upperEndpoint();//获取上边界10  没有抛异常
        // BoundType: 开闭枚举   CLOSED  OPEN
        range1.lowerBoundType();  //获取边界开闭类型   CLOSED
        //区间关系
        range1.encloses(range2); //1 是否包含2
        range1.isConnected(Range.closed(11, 15)); //是否相连,即边界相连 (1,2) (2,3) 则相连
        range1.intersection(Range.open(8,12));//交集  (8..10)
        range1.span(Range.open(8, 12));//并集 (1..12)
        //值包含
        range1.contains(5); //true
        range1.containsAll(Ints.asList(1,2,3,4,5));//true
    }
}
